package com.abai.doubi.server.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MQConfig {
    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }

    public static final String CONVERSATION_SAVE_QUEUE = "conversationSave.queue";
    public static final String CONVERSATION_SAVE_EXCHANGE = "conversationSave.exchange";
    public static final String CONVERSATION_SAVE_ROUTING_KEY = "conversation.save";
    @Bean
    public Queue conversationSaveQueue(){
        return new Queue(CONVERSATION_SAVE_QUEUE);
    }

    @Bean
    public TopicExchange conversationSaveExchange(){
        return new TopicExchange(CONVERSATION_SAVE_EXCHANGE);
    }

    @Bean
    public Binding documentBinding(){
        return BindingBuilder.bind(conversationSaveQueue())
                .to(conversationSaveExchange())
                .with(CONVERSATION_SAVE_ROUTING_KEY);
    }
}